import router from "@src/router";
import { OPEN_STATE_TEXT } from "@src/sp-reservation/constant/index.js";
import { resolveTimeAddZero } from "@src/common/reservation/config/index.js";
import base from "@src/store/base";
import { storeBindingsBehavior } from "mobx-miniprogram-bindings";

Component({
  behaviors: [storeBindingsBehavior, router.routerBehavior],
  storeBindings: [
    {
      store: base,
      fields: ["isiPhoneX", "themeColor", "themeTitleColor"],
    },
  ],
  options: {
    addGlobalClass: true,
    isHiddenTips: true,
  },
  properties: {
    imageList: {
      type: Array,
      value: [],
    },
    shopInfo: {
      type: Object,
      value: {},
    },
    isScrollToTop: {
      type: Boolean,
      value: false,
    },
  },

  data: { OPEN_STATE_TEXT, indicatorIndex: 1 },
  methods: {
    resolveTimeAddZero,
    handleToShopDetail(e) {
      // const {
      //   currentTarget: {
      //     dataset: {
      //       value: { value },
      //     },
      //   },
      // } = e;
      router.push({
        name: "reservation/detail",
        params: {
          shopId: this.data.shopInfo.shopId,
          // navIndex: e.currentTarget.dataset.index,
        },
      });
    },
    handleImageChange(e) {
      let indicatorIndex = e.detail.current + 1;
      this.setData({ indicatorIndex: indicatorIndex });
    },
    handleToShopList() {
      router.push({
        name: "reservation/shopList",
        events: {
          changeShop: (shopId) => {
            if (shopId !== this.data.shopId) {
              this.triggerEvent("changeShop", { shopId: shopId });
            }
          },
        },
      });
    },
    handleToMap() {
      console.log("去定位", this.data.shopInfo);
      const latitude = this.data.shopInfo.shopInfoResp.latitude;
      const longitude = this.data.shopInfo.shopInfoResp.longitude;
      const name = this.data.shopInfo.name;
      const address = this.data.shopInfo.address;
      wx.openLocation({ latitude, longitude, name, address, scale: 18 });
    },
    handleShowText() {
      this.setData({
        isHiddenTips: !this.data.isHiddenTips,
      });
    },
    callPhone(e) {
      if (!e.currentTarget.dataset.phone) {
        wx.showToast({ title: "该店铺暂未设置客服电话", icon: "none" });
        return;
      }
      console.log(e);
      wx.makePhoneCall({
        phoneNumber: e.currentTarget.dataset.phone, //仅为示例，并非真实的电话号码
      });
    },
  },
});
